const express = require('express')
const expressJoi = require('@escook/express-joi')
const {
  cancellation,
  logout,
  addCate,
  getCateList,
  delCategory,
  getSonCategoryList,
  editCategory,
  getCategoryById,
  addGoods,
  getGoodsList,
  delGoods,
  getGoodsById,
  filterGoodsList,
  editGoodsInfo,
  toggleNew,
  toggleRecommend,
  toggleNewOrRecommend,
  toggleBanner,
  getOrderList,
  getAccountList,
  delOrderById,
  getOrderById,
  delOrSendByOption,
  filterOrderList,
  getNeedDealOrderList,
  filterDealOrderList,
  orderDeliver
} = require('../router_handler/busUser')
const {
  add_cate_schema,
  add_goods_schema,
  edit_goods_schema,
  toggle_new_schema,
  toggle_recommend_schema,
  toggle_new_recommend_schema,
  toggle_banner_schema,
  del_order_schema,
  deal_order_option_schema,
  filter_order_list_schema,
  filter_deal_order_schema,
  get_order_schema,
  order_deliver_schema
} = require('../schema/busUserSchema')
const router = express.Router()

//#region
// 商家用户注销账号
router.post('/cancellation', cancellation)

// 商家用户退出登录
router.post('/logout', logout)

// 新增商品分类
router.post('/add/category', expressJoi(add_cate_schema), addCate)

// 获取一级商品分类列表
router.get('/category/list', getCateList)

// 删除分类
router.post('/del/category/:id', delCategory)

// 获取二级分类列表
router.get('/category/list/:id', getSonCategoryList)

// 修改分类信息
router.post('/edit/category/:id', expressJoi(add_cate_schema), editCategory)

// 根据id获取单个分类信息
router.get('/category/:id', getCategoryById)

// 发布商品
router.post('/add/goods', expressJoi(add_goods_schema), addGoods)

// 获取商品列表
router.get('/goods/list', getGoodsList)

// 删除商品
router.post('/del/goods/:id', delGoods)

// 根据id查看商品信息
router.get('/goods/:id', getGoodsById)

// 根据条件筛选商品
router.get('/filter/goods/list', filterGoodsList)

// 修改商品信息
router.post('/edit/goods/:id', expressJoi(edit_goods_schema), editGoodsInfo)

// 批量操作是否是新品还是推荐
router.post('/update/goods/neworrecommend', expressJoi(toggle_new_recommend_schema), toggleNewOrRecommend)

// 切换是否是新品
router.post('/update/goods/new/:id', expressJoi(toggle_new_schema), toggleNew)

// 切换是否是推荐商品
router.post('/update/goods/recommend/:id', expressJoi(toggle_recommend_schema), toggleRecommend)

// 切换是否是轮播图展示
router.post('/update/goods/banner/:id', expressJoi(toggle_banner_schema), toggleBanner)
//#endregion

// 获取商家订单数据
router.get('/get/order/list', getOrderList)

// 删除订单
router.post('/del/order', expressJoi(del_order_schema), delOrderById)

// 根据id获取订单详情数据
router.get('/get/order', expressJoi(get_order_schema), getOrderById)

// 批量操作订单
router.post('/deal/order/option', expressJoi(deal_order_option_schema), delOrSendByOption)

// 根据条件筛选订单数据
router.get('/filter/order/list', expressJoi(filter_order_list_schema), filterOrderList)

// 获取待处理订单数据
router.get('/deal/order/list', getNeedDealOrderList)

// 根据条件获取待处理订单数据
router.get('/filter/deal/order', expressJoi(filter_deal_order_schema), filterDealOrderList)

// 商家发货
router.post('/deliver/order', expressJoi(order_deliver_schema), orderDeliver)

// 获取商家账单数据
router.get('/get/account/list', getAccountList)

module.exports = router
